﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using SpeakupBackend.Classes;
using TableParsers;

namespace SpeakupBackend.Themes
{
    [Serializable]
    public partial class ClubTheme : INotifyPropertyChanged,
                                     IEquatable<ClubTheme>,
                                     IComparable,
                                     IComparable<ClubTheme>,
                                     ITheme
    {
        static public readonly ClassType ValidClassType = ClassType.Club;

        public ClubTheme(String name, ClubLevelGroup levelGroup)
        {
            m_name = name;
            m_levelGroup = levelGroup;
        }

        string m_name;
        public String Name
        {
            get
            {
                return m_name;
            }
        }

        ClubLevelGroup m_levelGroup;
        public ClubLevelGroup LevelGroup
        {
            get
            {
                return m_levelGroup;
            }
        }

        public override bool Equals(Object obj)
        {
            return Equals(obj as ClubTheme);            
        }

        public bool Equals(ClubTheme other)
        {
            return ClassHelper.IEquatableEquals(this, other);
        }

        public override int GetHashCode()
        {
            return ClassHelper.GetHashCode(Name, LevelGroup);
        }

        public int CompareTo(Object obj)
        {
            return CompareTo((ClubTheme)obj);
        }

        public int CompareTo(ClubTheme other)
        {
            if (Name != other.Name)
            {
                return Name.CompareTo(other.Name);
            }

            return LevelGroup.CompareTo(other.LevelGroup);
        }
        
        #region Comparison operators

        static public bool operator ==(ClubTheme rhs, ClubTheme lhs)
        {
            return ClassHelper.OperatorEqual(rhs, lhs);
        }

        static public bool operator !=(ClubTheme rhs, ClubTheme lhs)
        {
            return ClassHelper.OperatorNotEqual(rhs, lhs);
        }

        static public bool operator >(ClubTheme rhs, ClubTheme lhs)
        {
            return rhs.CompareTo(lhs) > 0;
        }

        static public bool operator <(ClubTheme rhs, ClubTheme lhs)
        {
            return rhs.CompareTo(lhs) < 0;
        }

        static public bool operator >=(ClubTheme rhs, ClubTheme lhs)
        {
            return rhs.CompareTo(lhs) >= 0;
        }

        static public bool operator <=(ClubTheme rhs, ClubTheme lhs)
        {
            return rhs.CompareTo(lhs) <= 0;
        }

        #endregion
    }

    public partial class ClubTheme : ThemeBase
    {
        public override bool IsCompatibleClass(Class cl)
        {
            //bad unit
            if (cl.Unit < Level.MinValidUnitNumber || cl.Unit > Level.MaxValidUnitNumber)
            {
                return false;
            }

            Level classLevel = Level.GetLevelByUnit(cl.Unit);

            return cl.Name.Type == ClassType.Club &&   
                   cl.Name.Name == Name &&
                   this.LevelGroup.ContainsLevel(classLevel);
        }
    }
}
